package javaRew;

import java.util.Date;

/**
 * Created by xjweng on 2017/1/30.
 */
public class Person2 {
    public String name;
    public int age;
    public Date birth;
    protected String email;
    private int id;
    public static int total = 0;

    /**
     * 静态代码块，只被执行一次，初始化类属性（静态变量）
     * 先于非静态代码块、构造器执行
     */
    static {
        System.out.println("静态代码块，最先执行");
        total = 100;
    }

    /**
     * 非静态代码块，先于构造器执行，每个实例都执行
     */
    {
        System.out.println("非静态代码块，先于构造器执行");
    }
    public Person2(){
        System.out.println("Person2 constructor");
        total++;
        id = total;
    }
    public String getInfo(){
        return "name: "+ name + "," +
                "age: " + age + "," +
                "birth: " + birth;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public int getId() {
        return id;
    }

    //在static方法内部只能访问类的static属性，不能访问类的非static属性
    public static int getTotal() {
        //id++ 非法
        return total;
    }

    public Date getBirth() {
        return birth;
    }
}
